//
//  UIImage+Category.swift
//  FirstSwiftProduct
//
//  Created by 范泽华 on 2017/11/6.
//  Copyright © 2017年 范泽华. All rights reserved.
//

import UIKit

extension UIImage {
    
    func drawRectWithCorner( radius: CGFloat, imageView: UIImageView) -> UIImage {
        //注意第三个选项的设置
        UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, false, UIScreen.main.scale)
        //在绘制之前先裁剪出一个圆形
        UIBezierPath.init(roundedRect: imageView.bounds, cornerRadius: radius).addClip()
        //图片在设置的圆形里面进行绘制
        imageView.image?.draw(in: imageView.bounds)
        //获取图片
        imageView.image = UIGraphicsGetImageFromCurrentImageContext()
        ////结束绘制
        UIGraphicsEndImageContext()
        
        return imageView.image!
    
    }
}
